function findDuplicate(n) {
  const map = new Map()
  this.forEach(i => {
    map.set(i, (map.get(i) || 0) + 1)
  })

  const result = []
  map.forEach((value, key) => {
    if (value >= n) result.push(key)
  })

  return result
}

Array.prototype.findDuplicate = findDuplicate

const a = [1, 2, 3, 4, 3, 3, 3, 2]

console.log(a.findDuplicate(2))
